class_name ChoppingState
extends NodeState

@export var player: Player
@export var animated_sprinte_2d: AnimatedSprite2D
@export var hit_component: HitComponent
@export var hit_component_colllision_shape: CollisionShape2D

func _ready() -> void:
	reset_hit()


func _on_next_transitions() -> void:
	if !animated_sprinte_2d.is_playing():
		transition.emit("Idle")


func _on_enter() -> void:
	hit_component.current_tool = DataTypes.Tools.AxeWood
	process_animation()
	process_hit()



func _on_exit() -> void:
	hit_component.current_tool = DataTypes.Tools.None
	animated_sprinte_2d.stop()
	reset_hit()


func process_animation():
	if player.player_direction == Vector2.UP:
		animated_sprinte_2d.play("chopping_back")
	elif player.player_direction == Vector2.DOWN:
		animated_sprinte_2d.play("chopping_front")
	elif player.player_direction == Vector2.LEFT:
		animated_sprinte_2d.play("chopping_left")
	elif player.player_direction == Vector2.RIGHT:
		animated_sprinte_2d.play("chopping_right")

func process_hit():
	if player.player_direction == Vector2.UP:
		hit_component_colllision_shape.position = Vector2(0, -19)
	elif player.player_direction == Vector2.DOWN:
		hit_component_colllision_shape.position = Vector2(0, 3)
	elif player.player_direction == Vector2.LEFT:
		hit_component_colllision_shape.position = Vector2(-9 , 0)
	elif player.player_direction == Vector2.RIGHT:
		hit_component_colllision_shape.position = Vector2(9, 0)
	hit_component_colllision_shape.disabled = false

func reset_hit():
	hit_component_colllision_shape.disabled = true
	hit_component_colllision_shape.position = Vector2.ZERO
